<? 
session_start();
if(!session_is_registered(uid)){
    echo "You have to login to view this page!</br></br>";
    echo "Click here to return to the "; 
    echo '<a href="./../index.php" title="Login">Login Page</a></br></br>';
    echo "Or sign up using this link ";
    echo '<a href="./../Registration/registration.html" title="Registration">Registration Page</a>';
exit();
}
else

    //Manual SQL Connection
    $con = mysql_connect("localhost", "root", "root") or die ( "Error connectiong to DB: ".mysql_error());
       
    mysql_select_db("reeferslog", $con) or die ( "Error selecting specific DB, reefeerslog: ".mysql_error());

if ($_GET['action'] == 'edit') {
    
    $qry = "SELECT * FROM pumps where user_id='".$_SESSION['uid']."' and id='".$_GET['id']."'";
    
    $results = mysql_query($qry)or die(mysql_error($con));

    extract(mysql_fetch_assoc($results));
    
}else {
    //set values blank
    
    //Date variables
    $day = 0;
    $month = 0;
    $year = 0;   
    
    //Function to make a valid date input
    $date_installed = $year."-".$month."-".$day;
    
    //pump
    $name = '';
    $quantity=0;
    $manufacturer = '';
    $gph = 0;
    $quantity = 0;
    $cost = 0;
}

?>

<html>
<head>
    <link rel="stylesheet" type="text/css" href="http://localhost/ReefersLogApp/CSS/Generalpagelayout.css" />
    
    <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'></script>
    <script type='text/javascript' src='./../scripts/js/jquery.ba-hashchange.min.js'></script>
    <script type='text/javascript' src='./../scripts/js/dynamicpage.js'></script>
    <title><?php echo ucfirst($_GET['action']); ?>Equip</title>
</head>
<div id="container">
	<div id="header">
            <h1>
		Reefers Log
            </h1>
	</div>
	<div id="navigation">
		<ul>
			<li><a href="./../WelcomePage/WelcomePage.php">Home</a></li>
			<li><a href="./../Profile/userprofile.php">Profile</a></li>
			<li><a href="./../Tools/tools.php">Tools</a></li>
			<li><a href="./../Logout/logout.php">Logout</a></li>
		</ul>
	</div>
	<div id="content-container">
		<div id="section-navigation">
                    <object id="loader" name="frameloader" type="text/html" data="http://localhost/ReefersLogApp/Welcome/WelcomePage.php/"></object>
			<ul>
                                <!--<li><a href="viewequip.php">View All Equipment</a></li>-->
				<li><a href="pumps.php">View Pumps</a></li>
				<li><a href="viewskimmer.php">View Skimmer</a></li>				
                                <li><a href="reactors.php">View Reactors</a></li>
                                <li><a href="./../Lighting/Lighting.html">Lights</a></li>
				
			</ul>
		</div>
		<div id="content">
                    <h2>
                        Your Aquarium Statistics:
                    </h2>
                    <p>
                        Edit your equipment logging regarding your aquarium. You may complete the form below or select another option
                        from the menu on the left to track your equipment.
                    </p>
		</div>
            <div id="content">
                    <h2>
                        Update the form below:
                    </h2>

<div align="center">
                 
                        <form action="commitedit.php?action=<?php echo $_GET['action']?>&type=pump&id=<?php echo $_GET['id']?>" method="post">                    
                        <table border="1">
                            <thead>
                            <th>Pumps</th>
                            </thead>
                             <tbody>

                                <tr>
                                    <td>Manufacturer:<input type="text" name="manufacturer" value="<? echo $manufacturer?>" /></td>
                                    <td>Name:<input type="text" name="name" value="<?echo $name?>" /></td>
                                    <td>GPH: <input type="text" name="gph" value="<?echo $gph?>" /></td>
                                </tr>
                                <tr>
                                    <td><label>Date Purchased (M/D/Y):</br></label><select name="month4">
                                            <option value="" SELECTED>
                                            <?php 
                                            $month = mysql_query("select id, date_installed from pumps where user_id='".$_SESSION['uid']."' and id='".$_GET['id']."' order by date_installed desc");
                                            while($row = mysql_fetch_array($month)){
                                               $selected = " SELECTED";
                                               if ( $row['date_installed'] == $date_installed){
                                                           $selected = " SELECTED";
                                                           list($year, $month, $day) = explode("-", $date_installed);
                                                        } else {
                                                           $selected = "";
                                                        }
                                                        echo '<OPTION value="'.$row['id'].'"'.$selected.'>'.$month.'</OPTION>'."\r\n";                                                                                                                                                                                 
                                            }
                                            ?>
                                        <option>01</option>
                                        <option>02</option>
                                        <option>03</option>
                                        <option>04</option>
                                        <option>05</option>
                                        <option>06</option>
                                        <option>07</option>
                                        <option>08</option>
                                        <option>09</option>
                                        <option>10</option>
                                        <option>11</option>
                                        <option>12</option>
                                    </select><select name="day4">
                                        <option value="" SELECTED>
                                            <?php 
                                            $d = mysql_query("select id, date_installed from pumps where user_id='".$_SESSION['uid']."' and id='".$_GET['id']."' order by date_installed desc");
                                            while($row = mysql_fetch_array($d)){
                                               $selected = " SELECTED";
                                               if ( $row['date_installed'] == $date_installed){
                                                           $selected = " SELECTED";
                                                           list($year, $month, $day) = explode("-", $date_installed);
                                                        } else {
                                                           $selected = "";
                                                        }
                                                        echo '<OPTION value="'.$row['id'].'"'.$selected.'>'.$day.'</OPTION>'."\r\n";                                                                                                                                                                                 
                                            }
                                            ?>
                                        <option>01</option>
                                        <option>02</option>
                                        <option>03</option>
                                        <option>04</option>
                                        <option>05</option>
                                        <option>06</option>
                                        <option>07</option>
                                        <option>08</option>
                                        <option>09</option>
                                        <option>10</option>
                                        <option>11</option>
                                        <option>12</option>
                                        <option>13</option>
                                        <option>14</option>
                                        <option>15</option>
                                        <option>16</option>
                                        <option>17</option>
                                        <option>18</option>
                                        <option>19</option>
                                        <option>20</option>
                                        <option>21</option>
                                        <option>22</option>
                                        <option>23</option>
                                        <option>24</option>
                                        <option>25</option>
                                        <option>26</option>
                                        <option>27</option>
                                        <option>28</option>
                                        <option>29</option>
                                        <option>30</option>
                                        <option>31</option>
                                    </select><select name="year4">
                                        <option value="" SELECTED>
                                            <?php 
                                            $y = mysql_query("select id, date_installed from pumps where user_id='".$_SESSION['uid']."' and id='".$_GET['id']."' order by date_installed desc");
                                            while($row = mysql_fetch_array($y)){
                                               $selected = " SELECTED";
                                               if ( $row['date_installed'] == $date_installed){
                                                           $selected = " SELECTED";
                                                           list($year, $month, $day) = explode("-", $date_installed);
                                                        } else {
                                                           $selected = "";
                                                        }
                                                        echo '<OPTION value="'.$row['id'].'"'.$selected.'>'.$year.'</OPTION>'."\r\n";                                                                                                                                                                                 
                                            }
                                            ?>
                                        <option>2020</option>
                                        <option>2019</option>
                                        <option>2018</option>
                                        <option>2017</option>
                                        <option>2016</option>
                                        <option>2015</option>
                                        <option>2014</option>
                                        <option>2013</option>
                                        <option>2012</option>
                                        <option>2011</option>
                                        <option>2010</option>
                                        <option>2009</option>
                                        <option>2008</option>
                                        <option>2007</option>
                                        <option>2006</option>
                                        <option>2005</option>
                                        <option>2004</option>
                                        <option>2003</option>
                                        <option>2002</option>
                                        <option>2001</option>
                                        <option>2000</option>
                                        <option>1999</option>
                                        <option>1998</option>
                                        <option>1996</option>
                                        <option>1995</option>
                                        <option>1994</option>
                                        <option>1993</option>
                                        <option>1992</option>
                                        <option>1991</option>
                                        <option>1990</option>
                                    </select></td>
                                    <td>Cost:<input type="text" name="cost" value="<?echo $cost?>" /></td>
                                    <td>Quantity:<input type="text" name="qty" value="<?echo $quantity?>" /></td>
                                </tr>
                                </tbody>         
</table>
                            <input align="center" type="submit" value="Update Pumps"/>
</div>
</form>
</div>
		<div id="aside">
                    <h3>
                        Info:
                    </h3>
                    <p>
                     You can edit your equipment options from the left.
                    </p>
		</div>
		<div id="footer">
			Copyright © ReefersLog, 2012, wkoester All Rights Reserved
		</div>
	</div>
</div>
</html>